/*
 * TransferPanel.java
 *
 * Created on August 28, 2008, 4:18 PM
 */

package jturbofile.gui2;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 *
 * @author  jbk
 */
public class TransferPanel extends javax.swing.JPanel {
    private Color backgroundHighlight = new Color(255,255,255);
    private Color backgroundNormal = new Color(238,238,238);

    class TransferPopupListener extends MouseAdapter {
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                transferPopup.show(e.getComponent(),
                           e.getX(), e.getY());
            }
        }
    } 
    
    /** Creates new form TransferPanel */
    public TransferPanel(Transfer transfer) {
        initComponents();
        if (transfer.isUpload()){
            directionLabel.setText("Upl");
        } else {
            directionLabel.setText("Dnl");
        }
        transferProgressBar.setString(transfer.getName());
        transferProgressBar.addMouseListener(new TransferPopupListener());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        transferPopup = new javax.swing.JPopupMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        directionLabel = new javax.swing.JLabel();
        transferProgressBar = new javax.swing.JProgressBar();

        jMenuItem1.setText("Cancel");
        transferPopup.add(jMenuItem1);

        setBackground(backgroundNormal);
        setMaximumSize(new java.awt.Dimension(32767, 18));
        setMinimumSize(new java.awt.Dimension(0, 18));
        setPreferredSize(new java.awt.Dimension(0, 18));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        directionLabel.setText("Upl");

        transferProgressBar.setValue(22);
        transferProgressBar.setRequestFocusEnabled(false);
        transferProgressBar.setString("some_interestingfile.mp4");
        transferProgressBar.setStringPainted(true);
        transferProgressBar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                transferProgressBarMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                transferProgressBarMouseExited(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(directionLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(transferProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(directionLabel)
                .addComponent(transferProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
    setBackground(backgroundHighlight);
    transferProgressBar.setBackground(backgroundHighlight);
}//GEN-LAST:event_formMouseEntered

private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
    setBackground(backgroundNormal);
    transferProgressBar.setBackground(backgroundNormal);    
}//GEN-LAST:event_formMouseExited

private void transferProgressBarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_transferProgressBarMouseEntered
    setBackground(backgroundHighlight);
    transferProgressBar.setBackground(backgroundHighlight);
}//GEN-LAST:event_transferProgressBarMouseEntered

private void transferProgressBarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_transferProgressBarMouseExited
    setBackground(backgroundNormal);
    transferProgressBar.setBackground(backgroundNormal);    
}//GEN-LAST:event_transferProgressBarMouseExited


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel directionLabel;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPopupMenu transferPopup;
    private javax.swing.JProgressBar transferProgressBar;
    // End of variables declaration//GEN-END:variables

}
